﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.Text;

namespace HQWeb.Login
{
    public partial class WorkPlatform : System.Web.UI.Page
    {
        int diffDay;
        protected void Page_Load(object sender, EventArgs e)
        {
            diffDay = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["diffDay"]);
            BindData();
        }

        private void BindData()
        {
            StringBuilder strHTML = new StringBuilder();
            string user_id = Session["USER_ID"].ToString();
            int branch_id = Convert.ToInt32(Session["BRANCH_ID"].ToString());
            BLL.Order.T_PUB_ORDER orderbll = new BLL.Order.T_PUB_ORDER();
            BLL.Order.T_PUB_ORDER_CONTANCT contactbll = new BLL.Order.T_PUB_ORDER_CONTANCT();
            Model.Order.T_PUB_ORDER_CONTANCT contactmodel = new Model.Order.T_PUB_ORDER_CONTANCT();
            List<Model.Order.T_PUB_ORDER> orderList = new List<Model.Order.T_PUB_ORDER>();
            DataTable ordertable = new DataTable();
            DataRow orderrow;
            ordertable = orderbll.GetOrderList("", user_id, "", "", "", "", "");
            DateTime weddingDate = new DateTime();
            DateTime currentDate = DateTime.Now;
            ArrayList neworderList = new ArrayList();
            ArrayList moneyorderList = new ArrayList();
            ArrayList chechorderList = new ArrayList();
            string order_ID;
            int row_index;
            for (int i = 0; i < ordertable.Rows.Count; i++)
            {
                weddingDate = Convert.ToDateTime(ordertable.Rows[i]["OrderDate"]);
                order_ID = ordertable.Rows[i]["ORDER_ID"].ToString();
                if (weddingDate >= currentDate)
                {
                    contactmodel = contactbll.GetModelByOrderID(order_ID);
                    if (contactmodel == null || contactmodel.DateTime < currentDate.AddDays(-diffDay))
                    {
                        neworderList.Add(i);
                    }
                }
                else
                {
                    if (ordertable.Rows[i]["Surplus"].ToString() != "0")
                    {
                        moneyorderList.Add(i);
                    }
                    if (ordertable.Rows[i]["CheckItem"].ToString() != "111")
                    {
                        chechorderList.Add(i);
                    }
                }
                
            }

            if (neworderList.Count > 0)
            {
                strHTML.Append("<table width=\"100%\" ><tr class=\"trclass\"><td class=\"title\">需跟进的订单</td></tr>");
                for (int i = 0; i < neworderList.Count; i++)
                {
                    row_index = Convert.ToInt32(neworderList[i]);
                    orderrow = ordertable.Rows[row_index];
                    strHTML.Append("<tr class=\"trclass\"><td class=\"tdclass\" align=\"left\">");
                    strHTML.Append(string.Format(" {0 }先生、{1}小姐 需要您持续跟进", orderrow["GROOM_NAME"].ToString(), orderrow["BRIDE_NAME"].ToString()));
                    strHTML.Append(string.Format("<a href=\"javascript:void(0)\" style=\"color: Blue\" onclick=\"PopBox('1','{0}')\"> 订单详细信息</a>", orderrow["ORDER_ID"]));
                    strHTML.Append(string.Format("<a href=\"javascript:void(0)\" style=\"color: Blue\" onclick=\"PopBox('2','{0}')\"> 添加记录</a>", orderrow["ORDER_ID"]));
                    strHTML.Append("</td></tr> ");
                }
                strHTML.Append("</table>");
            }
            else
            {
                strHTML.Append("<table width=\"100%\" ><tr class=\"trclass\"><td class=\"title\">暂无需跟进的订单</td></tr></table>");
            }
            //contact.InnerHtml = strHTML.ToString();
            //strHTML.Clear();
            if (moneyorderList.Count > 0)
            {
                strHTML.Append("<table width=\"100%\" ><tr class=\"trclass\"><td class=\"title\">余款未交齐的订单</td></tr>");
                for (int i = 0; i < moneyorderList.Count; i++)
                {
                    row_index = Convert.ToInt32(moneyorderList[i]);
                    orderrow = ordertable.Rows[row_index];
                    string surplus = orderrow["Surplus"].ToString();
                    strHTML.Append("<tr class=\"trclass\"><td class=\"tdclass\" align=\"left\">");
                    strHTML.Append(string.Format(" {0}先生 和 {1}小姐 还有余款{2}元未交", orderrow["GROOM_NAME"].ToString(), orderrow["BRIDE_NAME"].ToString(), surplus));
                    strHTML.Append(string.Format("<a href=\"javascript:void(0)\" style=\"color: Blue\" onclick=\"PopBox('1','{0}')\"> 订单详细信息</a>", orderrow["ORDER_ID"]));
                    strHTML.Append(string.Format("<a href=\"javascript:void(0)\" style=\"color: Blue\" onclick=\"PopBox('3','{0}')\"> 交款 </a>", orderrow["ORDER_ID"]));
                    strHTML.Append("</td></tr> ");
                }
                strHTML.Append("</table>");
            }
            else
            {
                strHTML.Append("<table width=\"100%\" ><tr class=\"trclass\"><td class=\"title\">暂无余款未交齐的订单</td></tr></table>");
            }
            //money.InnerHtml = strHTML.ToString();
            //strHTML.Clear();
            if (chechorderList.Count > 0)
            {
                strHTML.Append("<table width=\"100%\" ><tr class=\"trclass\"><td class=\"title\">物品未交接的订单</td></tr>");
                for (int i = 0; i < chechorderList.Count; i++)
                {
                    row_index = Convert.ToInt32(chechorderList[i]);
                    orderrow = ordertable.Rows[row_index];
                    strHTML.Append("<tr class=\"trclass\"> <td class=\"tdclass\" align=\"left\">");
                    strHTML.Append(string.Format(" {0}先生 和 {1}小姐 的婚礼物品还未交接完成", orderrow["GROOM_NAME"].ToString(), orderrow["BRIDE_NAME"].ToString()));
                    strHTML.Append(string.Format("<a href=\"javascript:void(0)\" style=\"color: Blue\" onclick=\"PopBox('1','{0}')\"> 定单详细信息</a>", orderrow["ORDER_ID"]));
                    strHTML.Append(string.Format("<a href=\"javascript:void(0)\" style=\"color: Blue\" onclick=\"PopBox('4','{0}')\"> 物品交接 </a>", orderrow["ORDER_ID"]));
                    strHTML.Append("</td> </tr> ");
                }
                strHTML.Append("</table>");
            }
            else
            {
                strHTML.Append("<table width=\"100%\" ><tr class=\"trclass\"><td class=\"title\">暂无物品未交接的订单</td></tr></table>");
            }
            //goods.InnerHtml = strHTML.ToString();
            all.InnerHtml = strHTML.ToString();
            //orderList = orderbll.GetRemindOrderList(branch_id);
        }
    }
}